package com.ybc.chinese.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;
import com.ybc.chinese.CustomShareListener;
import com.ybc.chinese.R;
import com.ybc.chinese.activity.AboutActivity;
import com.ybc.chinese.activity.CollectionActivity;
import com.ybc.chinese.activity.FeedBackActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * <p>更多<p/>
 * Created by Yubch on 17/2/18.
 */
public class MoreFragment extends BaseFragment {
    @Bind(R.id.iv_left)
    ImageView ivLeft;
    @Bind(R.id.tv_title)
    TextView tvTitle;

    private Context mCtx;
    private UMShareListener mShareListener;
    private ShareAction mShareAction;
    private UMWeb web;

    public static MoreFragment newInstance() {
        MoreFragment homeFragment = new MoreFragment();
        return homeFragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mCtx = getActivity();
        View view = inflater.from(mCtx).inflate(R.layout.fragment_more, container, false);
        ButterKnife.bind(this, view);
        initView();
        return view;
    }

    private void initView() {
        tvTitle.setText(getString(R.string.more));
        mShareListener = new CustomShareListener(getActivity());
        web = new UMWeb("http://a.app.qq.com/o/simple.jsp?pkgname=com.ybc.chinese");
        web.setTitle(getString(R.string.app_name));
        web.setThumb(new UMImage(getActivity(), R.mipmap.ic_logo));
        web.setDescription("最专业的"+getString(R.string.app_name)+"学习软件");
        /*增加自定义按钮的分享面板*/
        mShareAction = new ShareAction(getActivity()).setDisplayList(
                SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,
                /*SHARE_MEDIA.SINA, */SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
                .setShareboardclickCallback(new ShareBoardlistener() {
                    @Override
                    public void onclick(SnsPlatform snsPlatform, SHARE_MEDIA share_media) {
                            new ShareAction(getActivity()).withMedia(web).withText("有了它，妈妈再也不用担心我的学习了")
                                    .setPlatform(share_media)
                                    .setCallback(mShareListener)
                                    .share();
                    }
                });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick(R.id.layout_feedback)
    public void feedback() {
        Intent intent = new Intent(mCtx, FeedBackActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.layout_about)
    public void about() {
        Intent intent = new Intent(mCtx, AboutActivity.class);
        startActivity(intent);
    }

    @OnClick(R.id.layout_share)
    public void share() {
        mShareAction.open();
    }

    @OnClick(R.id.layout_collection)
    public void collection() {
        Intent intent = new Intent(mCtx, CollectionActivity.class);
        startActivity(intent);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(getActivity()).onActivityResult(requestCode, resultCode, data);

    }
}
